package com.thoughtworks;
import java.lang.Character;

public class InputConstrain {
    public static Boolean isCorrectRegister(String input){
//        用户名必须是2~10个任意字符
//        手机号必须是1开头的11位数字
//        邮箱必须包含@
//        密码必须是8~16个字符，含有至少一个数字和一个字母
        String[] info = input.split(",");
        String correct = "yes";
        if(!(info[0].length()<11&&info[0].length()>1)){
            correct = "no";
        }
        if(!(info[1].startsWith("1")&&info[1].length()==11)){
            correct = "no";
        }
        if(!(info[2].contains("@"))){
            correct = "no";
        }
        if(!(info[3].length()<17&&info[3].length()>7&&rightKey(info[3]))){
            correct = "no";
        }
        if(correct.equals("yes")){
            return true;
        } else {
            return false;
        }
    }

    public static Boolean isCorrectLogIn(String input){
//        用户名必须是2~10个任意字符
//        密码必须是8~16个字符，含有至少一个数字和一个字母
        String[] info = input.split(",");
        String correct = "yes";
        if(!(info[0].length()<11&&info[0].length()>1)){
            correct = "no";
        }
        if(!(info[1].length()<17&&info[1].length()>7&&rightKey(info[1]))){
            correct = "no";
        }
        if(correct.equals("yes")){
            return true;
        } else {
            return false;
        }
    }

    public static Boolean rightKey(String key){
        int numberDigit = 0;
        int numberChar = 0;
        for(int i=0;i<key.length();i++){
            if(Character.isLetter(key.charAt(i))){
                numberChar += 1;
            }
            if(Character.isDigit(key.charAt(i))){
                numberDigit += 1;
            }
        }
        if(numberChar>=1&&numberDigit>=1){
            return true;
        } else {
            return false;
        }
    }
}
